<template>
  <div class="turnintoRecord_wrap">
    <headTop :headClass="'white_header'">Transfer to a record</headTop>
    <div class="list_wrap" ref="scrollBox">
      <div class="tab_title">
        <div class="title_content">
          <span class="detail">details</span>
        </div>
        <!-- Small calendar -->
        <div class="date_wrap" @click="goSelectStart">
          <span class="date">{{showDate}}</span>
          <span class="iconfont icon-rili"></span>
        </div>
      </div>
       <!-- Record list -->
      <ul class="detail_list" ref="scrollBoxInner">
          <li class="public_none_data" v-if="!list.length && isRequest">No data</li>
          <li class="detail_item" v-for="(item, index) in list" :key="index" v-else>
            <div class="left_box">
              <p class="remark">{{item.typeName}}</p>
              <span class="create_time">{{item.create_at}}</span>
            </div>
            <div class="right_box">
              <p class="money">{{item.money}}</p>
            </div>
          </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  name: 'turnintoRecord',
  data () {
    return {
      isRequest: false, // Have you requested data?
      canRequest: true, // Can you request data, request lock?
      page: 1, // Paging default data
      hasMoreData: true, // Do you have more data?
      list: []
    };
  },
  methods: {
    // calendar event
    goSelectStart () {
      this.$store.commit('configDateWrap');
    },
    // Recording interface
    getInfo () {
      this.canRequest = false;
      this.axios.get('index/accountlog/treasure_log', {
        params: {
          page: this.page,
          time: this.startTime,
          type: 1
        }
      }).then(({data}) => {
        this.isRequest = true;
        if (data.code === 200) {
          this.canRequest = true;
          this.page++;
          let resObj;
          resObj = data.data;
          if (resObj.length < 10 || !resObj.length || !resObj) {
            this.hasMoreData = false;
          } else {
            this.hasMoreData = true;
          }
          this.list = this.list.concat(resObj);
        } else {
          this.Toast(data.message);
        }
      });
    }
  },
  watch: {
    showDate () {
      this.page = 1;
      this.isRequest = false;
      this.list = [];
      this.getInfo();
    }
  },
  computed: {
    showDate () {
      if (!this.$store.state.date.selectResult[1]) {
        return 'This month';
      } else {
        return `${this.$store.state.date.selectResult[0]}-${this.$store.state.date.selectResult[1]}`;
      }
    },
    startTime () {
      if (!this.$store.state.date.selectResult[1]) {
        return `${new Date().getFullYear()}-${new Date().getMonth() + 1}`;
      } else {
        return this.$store.state.date.selectResult.join('-');
      }
    },
    endTime () {
      if (!this.$store.state.date.selectResult[1]) {
        return `${new Date().getFullYear()}-${new Date().getMonth() + 2}`;
      } else {
        return `${this.$store.state.date.selectResult[0]}-${this.$store.state.date.selectResult[1] + 1}`;
      }
    }
  },
  mounted () {
    this.$refs.scrollBox.onscroll = (e) => {
      let bottomClient = this.$refs.scrollBoxInner.clientHeight - e.target.scrollTop - e.target.clientHeight;
      if (bottomClient < 50 && this.canRequest && this.hasMoreData) this.getInfo();
    };
    this.getInfo();
  }
};
</script>

<style lang="scss" scoped>
  @import '../style/public.scss';
  .turnintoRecord_wrap{
    width: 100%;
    background: #fff;
    height: 100%;
    padding-top: 90px;
    .list_wrap {
      height: 100%;
      overflow-y: scroll;
      &::before {
        background: #f4f5f7;
        display: block;
        width: 100%;
        height: 20px;
        content: '';
      }
      //  Record the head
      .tab_title {
        width: 100%;
        height: 95px;
        background: #fff;
        padding: 0 30px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1Px solid #e6e6e6;
        .title_content{
          height: 100%;
          line-height: 95px;
          font-size: 28px;
          color: #666666;
        }
        .date_wrap{
          font-size: 24px;
          display: flex;
          align-items: center;
          .date{
            margin-right: 17px;
            color: #666;
          }
          .icon-rili{
            font-size: 30px;
            color: #2f2f2f;
          }
        }
      }
      // Record list
      .detail_list {
        background: #fff;
        padding: 0 30px;
      .public_none_data {
        position: absolute;
        left: 0;
        right: 0;
        top: 40%;
        bottom: 0;
        margin: auto;
      }
        .detail_item {
          width: 100%;
          min-height: 142px;
          display: flex;
          justify-content: space-between;
          border-bottom: 1Px solid #e6e6e6;
          .remark, .money {
            font-size: 28px;
            color: #222222;
          }
          .create_time {
            font-size: 26px;
            color: #afafaf;
            padding-top: 10px;
          }
          .left_box, .right_box {
            display: flex;
            flex-direction: column;
            justify-content: space-around;
            padding: 25px 0;
          }
          .left_box {
            width: 80%;
          }
          .right_box {
            text-align: right;
            .money{
              color: $color;
            }
          }
        }
        // .detail_item:last-child {
        //   border-bottom: none;
        // }
      }
    }
  }
</style>
